home *** CD-ROM | disk | FTP | other *** search
/ Concrete Construction Image Library / Concrete Construction Image Library - Volume 1.iso / mac / ua.js < prev   
Text File  |  2001-08-14  |  5KB  |  165 lines

  1. // ua.js - Detect Browser
  2. // Requires JavaScript 1.1
  3. /*
  4. The contents of this file are subject to the Netscape Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/NPL/
  8.  
  9. Software distributed under the License is distributed on an "AS
  10. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. implied. See the License for the specific language governing
  12. rights and limitations under the License.
  13.  
  14. The Initial Developer of the Original Code is Bob Clary.
  15.  
  16. Contributor(s): Bob Clary, Original Work, Copyright 1999-2000
  17.                 Bob Clary, Netscape Communications, Copyright 2001
  18.  
  19. Alternatively, the contents of this file may be used under the
  20. terms of the GNU Public License (the "GPL"), in which case the
  21. provisions of the GPL are applicable instead of those above.
  22. If you wish to allow use of your version of this file only
  23. under the terms of the GPL and not to allow others to use your
  24. version of this file under the NPL, indicate your decision by
  25. deleting the provisions above and replace them with the notice
  26. and other provisions required by the GPL.  If you do not delete
  27. the provisions above, a recipient may use your version of this
  28. file under either the NPL or the GPL.
  29. */
  30.  
  31. // work around bug in xpcdom Mozilla 0.9.1
  32. window.saveNavigator = window.navigator;
  33.  
  34. // Handy functions
  35. function noop() {}
  36. function noerror() { return true; }
  37.  
  38. function defaultOnError(msg, url, line)
  39. {
  40.     // customize this for your site
  41.     if (top.location.href.indexOf('_files/errors/') == -1)
  42.         top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
  43. }
  44.  
  45. // Display Error page... 
  46. // XXX: more work to be done here
  47. //
  48. function reportError(message)
  49. {
  50.     // customize this for your site
  51.     if (top.location.href.indexOf('_files/errors/') == -1)
  52.         top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(message);
  53. }
  54.  
  55. function pageRequires(cond, msg, redirectTo)
  56. {
  57.     if (!cond)
  58.     {
  59.         msg = 'This page requires ' + msg;
  60.         top.location = redirectTo + '?msg=' + escape(msg);
  61.     }
  62.     // return cond so can use in <A> onclick handlers to exclude browsers
  63.     // from pages they do not support.
  64.     return cond;
  65. }
  66.  
  67. function detectBrowser()
  68. {
  69.     var oldOnError = window.onerror;
  70.     var element = null;
  71.     
  72.     window.onerror = defaultOnError;
  73.  
  74.     navigator.OS        = '';
  75.     navigator.version    = 0;
  76.     navigator.org        = '';
  77.     navigator.family    = '';
  78.  
  79.     var platform;
  80.     if (typeof(window.navigator.platform) != 'undefined')
  81.     {
  82.         platform = window.navigator.platform.toLowerCase();
  83.         if (platform.indexOf('win') != -1)
  84.             navigator.OS = 'win';
  85.         else if (platform.indexOf('mac') != -1)
  86.             navigator.OS = 'mac';
  87.         else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
  88.             navigator.OS = 'nix';
  89.     }
  90.  
  91.     var i = 0;
  92.     var ua = window.navigator.userAgent.toLowerCase();
  93.     
  94.     if (ua.indexOf('opera') != -1)
  95.     {
  96.         i = ua.indexOf('opera');
  97.         navigator.family    = 'opera';
  98.         navigator.org        = 'opera';
  99.         navigator.version    = parseFloat('0' + ua.substr(i+6), 10);
  100.     }
  101.     else if ((i = ua.indexOf('msie')) != -1)
  102.     {
  103.         navigator.org        = 'microsoft';
  104.         navigator.version    = parseFloat('0' + ua.substr(i+5), 10);
  105.         
  106.         if (navigator.version < 4)
  107.             navigator.family = 'ie3';
  108.         else
  109.             navigator.family = 'ie4'
  110.     }
  111.     else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
  112.     {
  113.         i = ua.lastIndexOf('/')
  114.         navigator.version = parseFloat('0' + ua.substr(i+1), 10);
  115.         navigator.family = 'gecko';
  116.  
  117.         if (ua.indexOf('netscape') != -1)
  118.             navigator.org = 'netscape';
  119.         else if (ua.indexOf('compuserve') != -1)
  120.             navigator.org = 'compuserve';
  121.         else
  122.             navigator.org = 'mozilla';
  123.     }
  124.     else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  125.     {
  126.         var is_major = parseFloat(navigator.appVersion);
  127.     
  128.         if (is_major < 4)
  129.             navigator.version = is_major;
  130.         else
  131.         {
  132.             i = ua.lastIndexOf('/')
  133.             navigator.version = parseFloat('0' + ua.substr(i+1), 10);
  134.         }
  135.         navigator.org = 'netscape';
  136.         navigator.family = 'nn' + parseInt(navigator.appVersion);
  137.     }
  138.     else if ((i = ua.indexOf('aol')) != -1 )
  139.     {
  140.         // aol
  141.         navigator.family    = 'aol';
  142.         navigator.org        = 'aol';
  143.         navigator.version    = parseFloat('0' + ua.substr(i+4), 10);
  144.     }
  145.  
  146.     navigator.DOMCORE1    = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
  147.     navigator.DOMCORE2    = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
  148.     navigator.DOMHTML    = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
  149.     navigator.DOMCSS1    = ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );
  150.  
  151.     navigator.DOMCSS2   = false;
  152.     if (navigator.DOMCORE1)
  153.     {
  154.         element = document.createElement('p');
  155.         navigator.DOMCSS2 = (typeof(element.style) == 'object');
  156.     }
  157.  
  158.     navigator.DOMEVENTS    = (typeof(document.createEvent) != 'undefined');
  159.  
  160.     window.onerror = oldOnError;
  161. }
  162.  
  163. detectBrowser();
  164.  
  165.